'''
Created on 31/01/2013

@author: Jorge
'''
from dataset.DatasetImplementations import DatasetForLibSVM, CustomDataSet
from Classifier import Classifier
from classifiers.SVMTreeExample import SVMTreeExample
from classifiers.svm_tree import SVMTree

class Info(Classifier):
    '''
    classdocs
    '''


    def __init__(self,dataset):
        '''
        Constructor
        '''
        X,Y,upper_Y = self._get_X_Y_upper_Y_vectors(dataset)
        classes = {}
        for i in range(len(Y)):
            try:
                (classes[Y[i]]).append(X[i])
            except KeyError:
                classes[Y[i]] = [ X[i] ]
                
        self.classes = classes
        
    def generate_frec(self):
        f = open('../data/info.txt', 'w')
        for c in self.classes.keys():
            print 'c=',c
            class_name = SVMTreeExample.categories[c]
            f.write(class_name+' -> '+str(len(self.classes[c]))+'\n')          
        f.close()
        
        
if __name__ == '__main__':
    data = CustomDataSet()
    dataset = data.get_training_set()
    dataset.extend(data.get_validation_set())
    test_set =( data.get_test_set() )
    dataset, test_set =  SVMTree.convert_example(dataset, test_set)
    dataset.extend(test_set)
    i = Info(dataset)
    i.generate_frec()